package com.ruoyi.activiti.service;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author danghf
 * @version 1.0
 * @date 2024/05/09 11:32
 * 角色用户查询服务
 * 查询上级，查询主任
 * 查询角色
 */
@Service
public class AssigneeService {
    private final ISysRoleService roleService;

    private final ISysUserService userService;

    public AssigneeService(ISysRoleService roleService, ISysUserService userService) {
        this.roleService = roleService;
        this.userService = userService;
    }

    public List<?> selectOptionsByUser(SysUser user){
        List<SysUser> sysUsers = userService.selectUserList(user);
        List<Option> res = new ArrayList<>();
        sysUsers.forEach(sysUser -> {
            Option option = new Option();
            option.setLabel(sysUser.getUserName());
            option.setValue(sysUser.getUserId().toString());
            res.add(option);
        });
        return res;
    }

    static class Option{
        private String label;
        private String value;

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public List<?> selectOptionsByDeptAndRole(Long roleId, Long deptId){

        return null;
    }

    /**
     * 根据用户id查询角色
     * @param userId userId
     */
    public List<Long> selectRoleListByUserId(Long userId){
        return roleService.selectRoleListByUserId(userId);
    }

    /**
     * 根据用户id查询角色名称
     * @param userId userId
     */
    public List<String> selectRoleNameListByUserId(Long userId){
        List<SysRole> sysRoles = roleService.selectRolesByUserId(userId);
        List<String> res = new ArrayList<>();
        sysRoles.forEach(sysRole -> {
            res.add(sysRole.getRoleName());
        });
        return res;
    }

    /**
     * 根据角色id获取角色名称
     * @param roleIds roleIds
     */
    public List<String> selectRoleNameListByGroupIds(List<Long> roleIds){
        return roleService.selectRoleNameListByGroupIds(roleIds);
    }

    /**
     * 根据用户id查询用户名称
     * @param candidateUserIds candidateUserIds
     */
    public List<String> selectUserNameListByUserIds(List<Long> candidateUserIds) {
        return userService.selectUserNameListByUserIds(candidateUserIds);
    }

}
